home *** CD-ROM | disk | FTP | other *** search
/ Champak 86 / (Vol 86) My Disc.iso / Games / pet_1112.swf / scripts / __Packages / com / Character.as next >
Text File  |  2009-04-14  |  11KB  |  415 lines

  1. class com.Character extends MovieClip
  2. {
  3.    var debugOn = false;
  4.    var _isIdle = false;
  5.    var _leftEarIsUp = true;
  6.    var _rightEarIsUp = false;
  7.    var _blueBarks = ["b1","b2","b3","b4"];
  8.    var _magentaBarks = ["b1","b2","b3","b4","b5"];
  9.    var _magentaBarksSad = ["s1","s2","s3","s4","s5"];
  10.    function Character()
  11.    {
  12.       super();
  13.       this.debug("character " + this + " has been initialized");
  14.       this.glow = new flash.filters.GlowFilter(16777215,1,3,3,30,3);
  15.       this.head = this.head;
  16.       this.body = this.body;
  17.       this.__set__isMagenta(false);
  18.       _global.setTimeout(this,"blink",100);
  19.    }
  20.    function attachClothes(bodyPart, linkage)
  21.    {
  22.       this.removeClothes(bodyPart);
  23.       switch(bodyPart)
  24.       {
  25.          case "head":
  26.             this.debug("Attaching " + linkage + " to the head");
  27.             this.head.gotoAndStop(linkage);
  28.             break;
  29.          case "eyes":
  30.             this.debug("Attaching " + linkage + " to the eyes");
  31.             this.head.glasses.gotoAndStop(linkage);
  32.             break;
  33.          case "neck":
  34.             this.debug("Attaching " + linkage + " to the neck");
  35.             this.body.neck.gotoAndStop(linkage);
  36.             break;
  37.          case "body":
  38.             this.debug("Attaching " + linkage + " to the body");
  39.             this.body.torso.gotoAndStop(linkage);
  40.             this.body.arm_r.gotoAndStop(linkage);
  41.             this.body.arm_l.gotoAndStop(linkage);
  42.             break;
  43.          case "legs":
  44.             this.debug("Attaching " + linkage + " to the legs");
  45.             this.body.torso.pants.gotoAndStop(linkage);
  46.             this.body.leg_r.gotoAndStop(linkage);
  47.             this.body.leg_l.gotoAndStop(linkage);
  48.             break;
  49.          default:
  50.             trace("Err: bodyPart:String in method attachClothes() must have a value of head, eyes, body, or legs");
  51.       }
  52.    }
  53.    function highlightIcon(bodyPart, glowOn)
  54.    {
  55.       if(glowOn)
  56.       {
  57.          this.glow.strength = 30;
  58.       }
  59.       else
  60.       {
  61.          this.glow.strength = 0;
  62.       }
  63.       switch(bodyPart)
  64.       {
  65.          case "head":
  66.             this.head.icon.filters = [this.glow];
  67.             break;
  68.          case "eyes":
  69.             break;
  70.          case "neck":
  71.             this.body.neck.icon.filters = [this.glow];
  72.             break;
  73.          case "body":
  74.             this.body.torso.icon.filters = [this.glow];
  75.             break;
  76.          case "legs":
  77.             break;
  78.          default:
  79.             trace("Err: bodyPart:String in method attachClothes() must have a value of head, eyes, body, or legs");
  80.       }
  81.    }
  82.    function removeClothes(bodyPart)
  83.    {
  84.       switch(bodyPart)
  85.       {
  86.          case "head":
  87.             this.debug("Removing from the head");
  88.             this.head.gotoAndStop(1);
  89.             break;
  90.          case "eyes":
  91.             this.debug("Removing from the eyes");
  92.             this.head.glasses.gotoAndStop(1);
  93.             break;
  94.          case "neck":
  95.             this.debug("Removing from the neck");
  96.             this.body.neck.gotoAndStop(1);
  97.             break;
  98.          case "body":
  99.             this.debug("Removing from the body");
  100.             this.body.torso.gotoAndStop(1);
  101.             this.body.arm_l.gotoAndStop(1);
  102.             this.body.arm_r.gotoAndStop(1);
  103.             break;
  104.          case "legs":
  105.             this.debug("Removing from the legs");
  106.             break;
  107.          case "all":
  108.             this.debug("Stripping clothes!");
  109.             this.head.gotoAndStop(1);
  110.             this.head.glasses.gotoAndStop(1);
  111.             this.body.torso.pants.gotoAndStop(1);
  112.             this.body.leg_r.gotoAndStop(1);
  113.             this.body.leg_l.gotoAndStop(1);
  114.             this.body.neck.gotoAndStop(1);
  115.             this.body.torso.gotoAndStop(1);
  116.             this.body.arm_l.gotoAndStop(1);
  117.             this.body.arm_r.gotoAndStop(1);
  118.             break;
  119.          default:
  120.             trace("Err: bodyPart:String in method removeClothes() must have a value of head, eyes, body, legs, or all");
  121.       }
  122.    }
  123.    function resetEverything()
  124.    {
  125.       this.__set__isIdle(false);
  126.       this.removeClothes("all");
  127.       this.armsReset();
  128.       this.headReset();
  129.       this.earReset();
  130.    }
  131.    function wave()
  132.    {
  133.       if(this._armsDown || this.body._currentframe != 2)
  134.       {
  135.          this.debug("Arms not in resting state. Adding to queue");
  136.          this.onArmsUp = function()
  137.          {
  138.             trace("executing onArmsUp");
  139.             this.body.gotoAndPlay("wave");
  140.             this.onArmsUp = null;
  141.          };
  142.          this.body.play();
  143.       }
  144.       else
  145.       {
  146.          this.debug("Arms at rest. Animating arms.");
  147.          this.body.gotoAndPlay("wave");
  148.       }
  149.    }
  150.    function armsToggle()
  151.    {
  152.       if(this.body._currentframe != 2)
  153.       {
  154.          this.onArmsUp = function()
  155.          {
  156.             this.body.gotoAndPlay("armsDown");
  157.             this.onArmsUp = null;
  158.          };
  159.          this.body.play();
  160.       }
  161.       else
  162.       {
  163.          this.body.gotoAndPlay("armsDown");
  164.       }
  165.    }
  166.    function armsReset()
  167.    {
  168.       if(this.body._currentframe != 2)
  169.       {
  170.          this.onArmsUp = function()
  171.          {
  172.             this.body.gotoAndPlay(1);
  173.             this.onArmsUp = null;
  174.          };
  175.          this.body.play();
  176.       }
  177.       else
  178.       {
  179.          this.body.gotoAndPlay(1);
  180.       }
  181.    }
  182.    function headTilt(dir)
  183.    {
  184.       this.moveEar("right");
  185.       if(!this.headReset())
  186.       {
  187.          this.gotoAndPlay(dir + "Tilt");
  188.       }
  189.    }
  190.    function headReset()
  191.    {
  192.       if(this._currentframe != 1)
  193.       {
  194.          this.play();
  195.          return true;
  196.       }
  197.       return false;
  198.    }
  199.    function moveEar(theEar, moveUp)
  200.    {
  201.       this.debug("Left ear is up? " + this._leftEarIsUp);
  202.       this.debug("Right ear is up? " + this._rightEarIsUp);
  203.       switch(theEar)
  204.       {
  205.          case "left":
  206.             this.head.ear_l.play();
  207.             break;
  208.          case "right":
  209.             this.head.ear_r.play();
  210.             break;
  211.          default:
  212.             trace("Error. Ear must be a string with value left or right");
  213.       }
  214.    }
  215.    function earReset()
  216.    {
  217.       if(!this._leftEarIsUp)
  218.       {
  219.          this.head.ear_l.play();
  220.       }
  221.       if(this._rightEarIsUp)
  222.       {
  223.          this.head.ear_r.play();
  224.       }
  225.    }
  226.    function blink(blinkOn)
  227.    {
  228.       if(blinkOn == undefined)
  229.       {
  230.          blinkOn = true;
  231.       }
  232.       clearInterval(this.blinkInterval);
  233.       if(blinkOn)
  234.       {
  235.          var _loc3_ = 3000 + Math.random() * 3000;
  236.          if(this._isMagenta)
  237.          {
  238.             this.head.eyes.gotoAndPlay("magentaBlink");
  239.          }
  240.          else
  241.          {
  242.             this.head.eyes.gotoAndPlay("blueBlink");
  243.          }
  244.          this.blinkInterval = setInterval(this,"blink",_loc3_);
  245.       }
  246.    }
  247.    function look(blinkOn)
  248.    {
  249.       if(blinkOn == undefined)
  250.       {
  251.          blinkOn = true;
  252.       }
  253.       clearInterval(this.lookInterval);
  254.       if(blinkOn)
  255.       {
  256.          var _loc2_ = 3000 + Math.random() * 5000;
  257.          this.head.eyes.play();
  258.          this.lookInterval = setInterval(this,"look",_loc2_);
  259.       }
  260.    }
  261.    function bark(frameLabel)
  262.    {
  263.       if(this._isMagenta)
  264.       {
  265.          this.head.mouth.magenta.gotoAndPlay(frameLabel);
  266.       }
  267.       else
  268.       {
  269.          this.head.mouth.blue.gotoAndPlay(frameLabel);
  270.       }
  271.    }
  272.    function barkRandom(isSad)
  273.    {
  274.       if(isSad == undefined)
  275.       {
  276.          isSad = false;
  277.       }
  278.       var _loc2_ = this.calcBark(isSad);
  279.       while(_loc2_ == this._prevBark)
  280.       {
  281.          this.debug("previous bark was " + this._prevBark + "... Recalculating");
  282.          _loc2_ = this.calcBark(isSad);
  283.       }
  284.       if(this._isMagenta)
  285.       {
  286.          if(!isSad)
  287.          {
  288.             this.bark(this._magentaBarks[_loc2_]);
  289.          }
  290.          else
  291.          {
  292.             this.bark(this._magentaBarksSad[_loc2_]);
  293.          }
  294.       }
  295.       else
  296.       {
  297.          this.bark(this._blueBarks[_loc2_]);
  298.       }
  299.       this._prevBark = _loc2_;
  300.    }
  301.    function calcBark(isSad)
  302.    {
  303.       var _loc2_ = undefined;
  304.       if(this._isMagenta)
  305.       {
  306.          if(!isSad)
  307.          {
  308.             _loc2_ = Math.floor(Math.random() * this._magentaBarks.length);
  309.          }
  310.          else
  311.          {
  312.             _loc2_ = Math.floor(Math.random() * this._magentaBarksSad.length);
  313.          }
  314.       }
  315.       else
  316.       {
  317.          _loc2_ = Math.floor(Math.random() * this._blueBarks.length);
  318.       }
  319.       this.debug("calculating bark: " + _loc2_);
  320.       return _loc2_;
  321.    }
  322.    function idleHead(dir)
  323.    {
  324.       clearInterval(this.headTiltInterval);
  325.       var _loc2_ = Math.random() * 2 >> 0;
  326.       var _loc3_ = 5000 + Math.random() * 10000;
  327.       if(_loc2_ == 0)
  328.       {
  329.          this.headTilt("left");
  330.       }
  331.       else
  332.       {
  333.          this.headTilt("right");
  334.       }
  335.       this.headTiltInterval = setInterval(this,"idleHead",_loc3_);
  336.    }
  337.    function set isIdle(isIdle)
  338.    {
  339.       this._isIdle = isIdle;
  340.       if(!this._isIdle)
  341.       {
  342.          this.look(false);
  343.          clearInterval(this.headTiltInterval);
  344.          clearInterval(this.earInterval);
  345.          clearInterval(this.armInterval);
  346.       }
  347.       else
  348.       {
  349.          this.look();
  350.          this.headTiltInterval = setInterval(this,"idleHead",6000,"left");
  351.          this.armInterval = setInterval(this,"armsToggle",7000);
  352.       }
  353.    }
  354.    function set isMagenta(val)
  355.    {
  356.       this.setCharacter(val);
  357.    }
  358.    function get isMagenta()
  359.    {
  360.       return this._isMagenta;
  361.    }
  362.    function setCharacter(isMagenta)
  363.    {
  364.       this.debug("setting magenta mode to " + isMagenta);
  365.       this._isMagenta = isMagenta;
  366.       this.head.nose.blue._visible = !isMagenta;
  367.       this.head.nose.magenta._visible = isMagenta;
  368.       this.head.blue._visible = !isMagenta;
  369.       this.head.magenta._visible = isMagenta;
  370.       this.head.mouth.blue._visible = !isMagenta;
  371.       this.head.mouth.magenta._visible = isMagenta;
  372.       if(isMagenta)
  373.       {
  374.          this.head.eyes.gotoAndPlay("magenta");
  375.       }
  376.       else
  377.       {
  378.          this.head.eyes.gotoAndPlay("blue");
  379.       }
  380.       if(isMagenta)
  381.       {
  382.          this.head.ear_r.gotoAndStop("magenta");
  383.       }
  384.       else
  385.       {
  386.          this.head.ear_r.gotoAndStop("blue");
  387.       }
  388.       if(isMagenta)
  389.       {
  390.          this.head.ear_l.gotoAndStop("magenta");
  391.       }
  392.       else
  393.       {
  394.          this.head.ear_l.gotoAndStop("blue");
  395.       }
  396.       this.body.torso.blue._visible = !isMagenta;
  397.       this.body.torso.magenta._visible = isMagenta;
  398.       this.body.arm_r.blue._visible = !isMagenta;
  399.       this.body.arm_r.magenta._visible = isMagenta;
  400.       this.body.arm_l.blue._visible = !isMagenta;
  401.       this.body.arm_l.magenta._visible = isMagenta;
  402.       this.body.leg_r.blue._visible = !isMagenta;
  403.       this.body.leg_r.magenta._visible = isMagenta;
  404.       this.body.leg_l.blue._visible = !isMagenta;
  405.       this.body.leg_l.magenta._visible = isMagenta;
  406.    }
  407.    function debug(msg)
  408.    {
  409.       if(this.debugOn)
  410.       {
  411.          trace(msg);
  412.       }
  413.    }
  414. }
  415.